package com.rc.saas.mini.service.market;

import com.rc.saas.mini.mapper.market.MarketActivityMemberMapper;
import com.rc.saas.mini.model.market.MarketActivityMember;
import com.rc.saas.mini.model.market.MarketActivityMemberExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MarketActivityMemberServiceImpl implements MarketActivityMemberService {
    @Autowired
    private MarketActivityMemberMapper marketActivityMemberMapper;

    @Override
    public MarketActivityMemberMapper getMapper() {
        return marketActivityMemberMapper;
    }

    @Override
    public int countByMarketActivityId(Long marketActivityId, Long memberId) {
        MarketActivityMemberExample example = new MarketActivityMemberExample();
        example.createCriteria().andMemberIdEqualTo(memberId).andMarketActivityIdEqualTo(marketActivityId);
        Long count = marketActivityMemberMapper.countByExample(example);
        return count.intValue();
    }

    @Override
    public void insertRetrunId(MarketActivityMember marketActivityMember) {
        marketActivityMemberMapper.insertReturnId(marketActivityMember);
    }

    @Override
    public MarketActivityMember selectByAcitvity(Long marketActivityId, Long memberId) {
        MarketActivityMemberExample example = new MarketActivityMemberExample();
        example.createCriteria().andMemberIdEqualTo(memberId).andMarketActivityIdEqualTo(marketActivityId);
        return  marketActivityMemberMapper.selectByExample(example).stream().findFirst().orElseGet(()->null);
    }
}
